﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using EventAggregationQuickStart;
using System.Windows.Forms;

namespace EventAggregationQuickstart
{
    public class RegionManagerService : IRegionManagerService
    {
        public RegionManagerService()
        {
            Regions = new Dictionary<string, System.Windows.Forms.Control>();
        }

        #region IRegionManager Members

        public System.Windows.Forms.Control ShellContainer
        {
            set 
            {
                foreach (Control item in value.Controls)
                {
                    if (item.GetType() == typeof(Panel))
                    {
                        Regions.Add(item.Name, item);
                    }
                }; 
            }
        }

        public Dictionary<string, System.Windows.Forms.Control> Regions
        {
            get; 
            private set;
        }

        public void ShowView(string region, IView view)
        {
            // Just display the view in the named region 
            Regions[region].Controls.Add((Control)view);
            ((Control)view).Dock = DockStyle.Fill;
            ((Control)view).Visible = true;
            Regions[region].Refresh();
        }

        #endregion
    }
}
